﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SceneLib
{
    public class MathUtils
    {
        public static float[] GetVector3Array(Vector v)
        {
            float[] array = new float[3];
            array[0] = v.x;
            array[1] = v.y;
            array[2] = v.z;
            return array;
        }

        public static float[] GetVector4Array(Vector v)
        {
            float[] array = new float[4];
            array[0] = v.x;
            array[1] = v.y;
            array[2] = v.z;
            array[3] = 1;
            return array;
        }

        public static Vector Barycentric3D(Vector p, Vector a, Vector b, Vector c)
        {
            Vector n = Vector.Cross3(b - a, c - a);
            Vector na = Vector.Cross3(c - b, p - b);
            Vector nb = Vector.Cross3(a - c, p - c);
            Vector nc = Vector.Cross3(b - a, p - a);
            float alpha = Vector.Dot3(n, na) / Vector.Dot3(n, n);
            float beta = Vector.Dot3(n, nb) / Vector.Dot3(n, n);
            float gamma = Vector.Dot3(n, nc) / Vector.Dot3(n, n);
            Vector bar = new Vector(alpha, beta, gamma);
            return bar;
        }

       
    }
}
